﻿Imports System.ComponentModel
Imports DevExpress.Skins
Imports DevExpress.LookAndFeel
Imports DevExpress.UserSkins
Imports DevExpress.XtraBars
Imports DevExpress.XtraBars.Ribbon
Imports DevExpress.XtraBars.Helpers
Imports DevExpress.XtraSplashScreen
Imports DevExpress.XtraEditors
Imports DevExpress.XtraGrid.Views.Base

Public Class KH_BanHang
    Dim Ma As String
    Dim State As Integer = 0 'trạng thái form '0 mặc định'1 tạo mới'2 sửa '3 xoa
    Private Sub BHBanHangBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Validate()
        Me.BHBanHangBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.PCV_FISHDataSet)

    End Sub
    Private Sub setReadonly(ByVal b As Boolean)
        Me.MaTextEdit.Properties.ReadOnly = b
        Me.ManghiepvuSearchLookUpEdit.Properties.ReadOnly = b
        Me.SochungtuTextEdit.Properties.ReadOnly = b
        Me.NgaychungtuDateEdit.Properties.ReadOnly = b
        Me.SohoadonTextEdit.Properties.ReadOnly = b
        Me.NgaychungtuDateEdit.Properties.ReadOnly = b
        Me.SotokhaiHQTextEdit.Properties.ReadOnly = b
        Me.NgaytokhaiHQDateEdit.Properties.ReadOnly = b
        Me.TygiatokhaiHQTextEdit.Properties.ReadOnly = b
        Me.MakhachhangSearchLookUpEdit.Properties.ReadOnly = b
        Me.TenkhachhangTextEdit.Properties.ReadOnly = b
        Me.DiachiTextEdit.Properties.ReadOnly = b
        Me.HinhthucthanhtoanSearchLookUpEdit.Properties.ReadOnly = b
        Me.NgaythanhtoanDateEdit.Properties.ReadOnly = b
        Me.DieukiengiaohangTextEdit.Properties.ReadOnly = b
        Me.DiengiaiTextEdit.Properties.ReadOnly = b
        Me.PhuongtienvanchuyenTextEdit.Properties.ReadOnly = b
        Me.SoxeTextEdit.Properties.ReadOnly = b
        Me.NhanviensaleSearchLookUpEdit.Properties.ReadOnly = b
        Me.PhongbanSearchLookUpEdit.Properties.ReadOnly = b
        Me.MachuongtrinhkhuyenmaiSearchLookUpEdit.Properties.ReadOnly = b
        Me.KyketoanTextEdit.Properties.ReadOnly = b
        Me.TinhtrangSearchLookUpEdit.Properties.ReadOnly = b
        Me.NgayhoadonDateEdit.Properties.ReadOnly = b
        Me.SoSOTextEdit.Properties.ReadOnly = b
        Me.SodongoiTextEdit.Properties.ReadOnly = b
        Me.SocontTextEdit.Properties.ReadOnly = b
        Me.SohopdongTextEdit.Properties.ReadOnly = b
        Me.BanggiaSearchLookUpEdit.Properties.ReadOnly = b
        Me.LoaitienSearchLookUpEdit.Properties.ReadOnly = b
        Me.NguyenteTextEdit.Properties.ReadOnly = b
        Me.ThanhtienvndTextEdit.Properties.ReadOnly = b
        Me.TygianganhangTextEdit.Properties.ReadOnly = b
        If b Then
            Me.IGridView1.OptionsBehavior.Editable = False
        Else
            Me.IGridView1.OptionsBehavior.Editable = True
        End If
        If b Then 'trong trạng thái readonly  thì không cho nhập và dòng trống thêm ở cuối
            Me.IGridView1.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.None
        Else  'cho thêm dòng trống ở cuối (khác form đơn - bỏ dòng : And State = 1)
            Me.IGridView1.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom
        End If
        If b Then
            'dxprovidervalidation
            Me.DxValidationProvider1.ValidationMode = DXErrorProvider.ValidationMode.Manual
            setButtonTrangThaiSua(False)
        Else
            Me.DxValidationProvider1.ValidationMode = DXErrorProvider.ValidationMode.Auto
            setButtonTrangThaiSua(True)
        End If
    End Sub
    Private Sub setButtonTrangThaiSua(ByVal b As Boolean) 'set nút lưu và xóa - khi ở trạng thái sửa thì mới cho phép thao tác trên nó (enable = true) - các trạng thái khác thì không cho (enable = false)
        Me.BarButtonItemLuu.Enabled = b
        Me.BarButtonItemXoa.Enabled = b
        If b Then 'xử lý nút sửa (nếu nút lưu - xóa cho phép thì sửa ko cho phép và ngược lại)
            Me.BarButtonItemSua.Enabled = False
        Else
            Me.BarButtonItemSua.Enabled = True
        End If
        setButtonChiTietTrangThaiSua(b)
    End Sub
    Private Sub setButtonChiTietTrangThaiSua(ByVal b As Boolean)
        Me.BarButtonItemTaoMoiChiTiet.Enabled = b
        Me.BarButtonItemXoaChiTiet.Enabled = b
        Me.BarButtonItemHuyThayDoiChiTiet.Enabled = b
    End Sub
    Private Sub KH_HangHoa_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SplashScreenManager.ShowForm(GetType(WaitForm1))
        'Me.Dmhanghoa_donvitinhTableAdapter.Fill(Me.PCV_FISHDataSet.dmhanghoa_donvitinh)
        'Me.DmhanghoaTableAdapter.Fill(Me.PCV_FISHDataSet.dmhanghoa)
        Me.DmkhachhangTableAdapter.Fill(Me.PCV_FISHDataSet.dmkhachhang)
        Me.DmnghiepvuTableAdapter.Fill(Me.PCV_FISHDataSet.dmnghiepvu)
        Me.BHBanHangTableAdapter.Fill(Me.PCV_FISHDataSet.BHBanHang)
        Me.BHBanHangChiTietTableAdapter.Fill(Me.PCV_FISHDataSet.BHBanHangChiTiet)
        'Me.GetDMNhanVien_NhanVienBanHangTableAdapter.Fill(Me.PCV_FISHDataSet.getDMNhanVien_NhanVienBanHang)
        'Me.GetPhanLoai_ThanhToanTableAdapter.Fill(Me.PCV_FISHDataSet.getPhanLoai_ThanhToan)
        Me.DmphongbanTableAdapter.Fill(Me.PCV_FISHDataSet.dmphongban)
        'Me.GetPhanLoai_TienTeTableAdapter.Fill(Me.PCV_FISHDataSet.getPhanLoai_TienTe)
        'Me.GetPhanLoai_TinhTrangPhieuTableAdapter.Fill(Me.PCV_FISHDataSet.getPhanLoai_TinhTrangPhieu)
        'Me.DMTaiKhoanKeToanCap2TableAdapter.Fill(Me.PCV_FISHDataSet.DMTaiKhoanKeToanCap2)
        Me.IGridView1.BestFitColumns() 'tự co dãn các cột của igridview dựa vào độ dài cột dữ liệu
        Me.MakhachhangSearchLookUpEditView.BestFitColumns()
        'Me.IGridView2.BestFitColumns()
        'Me.IGridView3.BestFitColumns()
        setReadonly(True)
        SplashScreenManager.CloseForm()
    End Sub

    Private Sub BarButtonItemTaoMoi_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemTaoMoi.ItemClick
        'addnew
        'Me.BHBanHangBindingSource.AddNew()
        'tạo mã
        'Me.MaTextEdit.EditValue = "BH" & System.Guid.NewGuid.ToString()

        'focus
        Me.ManghiepvuSearchLookUpEdit.Focus()
        Me.setReadonly(False)
        'Mã
        Dim row As DataRowView = CType(BHBanHangBindingSource.AddNew(), DataRowView)
        Me.Ma = "BH" & System.Guid.NewGuid.ToString()
        row("ma") = Ma
        'mặc định
        Me.NgaychungtuDateEdit.EditValue = Today
        Me.NgayhoadonDateEdit.EditValue = Today
        Me.NgaythanhtoanDateEdit.EditValue = Today
        Me.NgaytokhaiHQDateEdit.EditValue = Today
        Me.TygianganhangTextEdit.EditValue = 1
        Me.LoaitienSearchLookUpEdit.EditValue = "VND"
        Me.ThanhtienvndTextEdit.EditValue = "0"
        Me.NguyenteTextEdit.EditValue = "0"
    End Sub

    Private Sub MakhachhangSearchLookUpEdit_EditValueChanging(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ChangingEventArgs) Handles MakhachhangSearchLookUpEdit.EditValueChanging
        Dim editor As SearchLookUpEdit = CType(sender, SearchLookUpEdit)
        Dim rowhandle As Integer = Me.MakhachhangSearchLookUpEdit.Properties.GetIndexByKeyValue(e.NewValue)
        Me.TenkhachhangTextEdit.EditValue = editor.Properties.View.GetRowCellValue(rowhandle, "ten")
        Me.DiachiTextEdit.EditValue = editor.Properties.View.GetRowCellValue(rowhandle, "diachi")
    End Sub

    Private Sub BarButtonItemLuu_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemLuu.ItemClick
        Try
            Me.IGridView1.PostEditor()
            Me.IGridView1.UpdateCurrentRow()
            Me.IGridView1.CloseEditor()
            Me.BHBanHangBindingSource.EndEdit() 'end edit trước khi lưu - ghi những thay đổi 
            Me.FKBHBanHangChiTietBHBanHangBindingSource.EndEdit()
            If Me.PCV_FISHDataSet.HasChanges Then 'coi có thay đổi dữ liệu hay ko ?
                If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn 'Lưu' không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
                    Try
                        Me.TableAdapterManager.UpdateAll(Me.PCV_FISHDataSet)
                        Me.State = 0 'trở về trạng thái mặc định 0
                        Me.setReadonly(True) 'set lại readonly
                        setButtonTrangThaiSua(False) 'set lại nút 
                    Catch ex As Exception
                        DevExpress.XtraEditors.XtraMessageBox.Show("Xảy ra lỗi :" & ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    End Try
                End If
            Else 'nếu ko thay đổi dữ liệu
                DevExpress.XtraEditors.XtraMessageBox.Show("Chưa có thay đổi dữ liệu ?", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Me.setReadonly(True) 'set lại readonly
                setButtonTrangThaiSua(False) 'set lại nút 
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message) 'tung message khi có ngoại lệ
        End Try
    End Sub

    Private Sub NhanviensaleSearchLookUpEdit_EditValueChanging(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ChangingEventArgs) Handles NhanviensaleSearchLookUpEdit.EditValueChanging
        Dim editor As SearchLookUpEdit = CType(sender, SearchLookUpEdit)
        Dim rowhandle As Integer = Me.NhanviensaleSearchLookUpEdit.Properties.GetIndexByKeyValue(e.NewValue)
        Me.DmphongbanBindingSource.Filter = "ma = '" & editor.Properties.View.GetRowCellValue(rowhandle, "bophan") & "'"
    End Sub

    Private Sub BarButtonItemSua_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemSua.ItemClick
        Me.setReadonly(False)
        Me.State = 2
    End Sub

    Private Sub IGridView1_CellValueChanged(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs) Handles IGridView1.CellValueChanged
        If e.Column.FieldName = "dongianguyente" Or e.Column.FieldName = "soluonggiao" Or e.Column.FieldName = "dongiavnd" Or e.Column.FieldName = "tilethueGTGT" Then
            Try
                IGridView1.SetRowCellValue(e.RowHandle, IGridView1.Columns("thanhtiennguyente"), CDec(Me.IGridView1.GetRowCellValue(e.RowHandle, IGridView1.Columns("soluonggiao"))) * CDec(Me.IGridView1.GetRowCellValue(e.RowHandle, IGridView1.Columns("dongianguyente"))))
            Catch ex As Exception
                IGridView1.SetRowCellValue(e.RowHandle, IGridView1.Columns("thanhtiennguyente"), 0)
            End Try
            Try
                IGridView1.SetRowCellValue(e.RowHandle, IGridView1.Columns("thanhtienvnd"), CDec(Me.IGridView1.GetRowCellValue(e.RowHandle, IGridView1.Columns("soluonggiao"))) * CDec(Me.IGridView1.GetRowCellValue(e.RowHandle, IGridView1.Columns("dongiavnd"))))
            Catch ex As Exception
                IGridView1.SetRowCellValue(e.RowHandle, IGridView1.Columns("thanhtienvnd"), 0)
            End Try
            Try
                IGridView1.SetRowCellValue(e.RowHandle, IGridView1.Columns("tienthueGTGT"), CDec(Me.IGridView1.GetRowCellValue(e.RowHandle, IGridView1.Columns("thanhtienvnd"))) * CDec(Me.IGridView1.GetRowCellValue(e.RowHandle, IGridView1.Columns("tilethueGTGT"))) / 100)
            Catch ex As Exception
                IGridView1.SetRowCellValue(e.RowHandle, IGridView1.Columns("tienthueGTGT"), 0)
            End Try
        End If
        Me.IGridView1.UpdateSummary()
    End Sub
    Private Sub IGridView1_InitNewRow(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs) Handles IGridView1.InitNewRow
        Me.BHBanHangBindingSource.EndEdit()
        Me.IGridView1.SetFocusedRowCellValue("ma", Ma)
        Me.IGridView1.SetFocusedRowCellValue("uid", System.Guid.NewGuid().ToString)
        Me.IGridView1.SetFocusedRowCellValue("manghiepvu", Me.ManghiepvuSearchLookUpEdit.EditValue)
        Me.IGridView1.SetFocusedRowCellValue("sochungtu", Me.SochungtuTextEdit.EditValue)
        Me.IGridView1.SetFocusedRowCellValue("ngaychungtu", CDate(Me.NgaychungtuDateEdit.EditValue))
        Me.IGridView1.SetFocusedRowCellValue("soluongSO", 0)
        Me.IGridView1.SetFocusedRowCellValue("soluonggiao", 0)
        Me.IGridView1.SetFocusedRowCellValue("dongianguyente", 0)
        Me.IGridView1.SetFocusedRowCellValue("dongiavnd", 0)
        Me.IGridView1.SetFocusedRowCellValue("thanhtiennguyente", 0)
        Me.IGridView1.SetFocusedRowCellValue("thanhtienvnd", 0)
        Me.IGridView1.SetFocusedRowCellValue("tilethueGTGT", 0)
        Me.IGridView1.SetFocusedRowCellValue("tienthueGTGT", 0)
        Me.IGridView1.SetFocusedRowCellValue("chiphiban", 0)
        Me.IGridView1.SetFocusedRowCellValue("tilethueNK", 0)
        Me.IGridView1.SetFocusedRowCellValue("tienthueNK", 0)
        Me.IGridView1.SetFocusedRowCellValue("chietkhau", 0)
        Me.IGridView1.SetFocusedRowCellValue("chenhlech", 0)
    End Sub

    Private Sub BarButtonItemThoat_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemThoat.ItemClick
        Me.Dispose() 'giải phóng ram
        Me.Close() 'đóng
    End Sub

    Private Sub BarButtonItemTaoMoiChiTiet_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemTaoMoiChiTiet.ItemClick
        Me.IGridView1.MoveLast()
        Me.IGridView1.Focus()
        Me.IGridView1.AddNewRow()
        Me.IGridView1.FocusedColumn = Me.IGridView1.VisibleColumns(0)
        Me.IGridView1.ShowEditor()
    End Sub

    'Private Sub RepositoryItemSearchLookUpEdit5_EditValueChanging(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ChangingEventArgs) Handles RepositoryItemSearchLookUpEdit5.EditValueChanging
    'Dim editor As SearchLookUpEdit = CType(sender, SearchLookUpEdit)
    'Dim rowHandle As Integer = Editor.Properties.GetIndexByKeyValue(e.NewValue)
    'If Me.IGridView1.IsNewItemRow(IGridView1.FocusedRowHandle) Then
    '    'And IGridView1.GetRow(IGridView1.FocusedRowHandle) Is DBNull.Value Then
    '    Me.IGridView1.AddNewRow()
    '    Me.IGridView1.MovePrev()
    'End If
    '    IGridView1.SetFocusedRowCellValue("mahang", editor.Properties.View.GetRowCellValue(rowHandle, "ma"))
    '    IGridView1.SetFocusedRowCellValue("tenhang", editor.Properties.View.GetRowCellValue(rowHandle, "ten1"))
    '    IGridView1.SetFocusedRowCellValue("dvt", editor.Properties.View.GetRowCellValue(rowHandle, "donvitinh"))
    'End Sub

    Private Sub MakhachhangSearchLookUpEdit_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles MakhachhangSearchLookUpEdit.Enter
        SendKeys.Send("%{DOWN}")
    End Sub

    Private Sub NgaychungtuDateEdit_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles NgaychungtuDateEdit.GotFocus
        Me.NgaychungtuDateEdit.ShowPopup()
    End Sub

    Private Sub NhanviensaleSearchLookUpEdit_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles NhanviensaleSearchLookUpEdit.Enter
        SendKeys.Send("%{DOWN}")
    End Sub

    Private Sub PhongbanSearchLookUpEdit_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PhongbanSearchLookUpEdit.Enter
        SendKeys.Send("%{DOWN}")
    End Sub

    Private Sub HinhthucthanhtoanSearchLookUpEdit_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles HinhthucthanhtoanSearchLookUpEdit.Enter
        SendKeys.Send("%{DOWN}")
    End Sub

    Private Sub LoaitienSearchLookUpEdit_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles LoaitienSearchLookUpEdit.Enter
        SendKeys.Send("%{DOWN}")
    End Sub

    Private Sub TinhtrangSearchLookUpEdit_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TinhtrangSearchLookUpEdit.Enter
        SendKeys.Send("%{DOWN}")
    End Sub

    Private Sub BarButtonItemFirst_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemFirst.ItemClick
        Me.BHBanHangBindingSource.MoveFirst()
    End Sub

    Private Sub BarButtonPrevious_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonPrevious.ItemClick
        Me.BHBanHangBindingSource.MovePrevious()
    End Sub

    Private Sub BarButtonNext_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonNext.ItemClick
        Me.BHBanHangBindingSource.MoveNext()
    End Sub

    Private Sub BarButtonLast_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonLast.ItemClick
        Me.BHBanHangBindingSource.MoveLast()
    End Sub

    Private Sub BarButtonItemFirstChiTiet_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemFirstChiTiet.ItemClick
        'If Me.LayoutControlGroupHangHoa.IsInTabbedGroup Then
        'Me.FKBHBanHangChiTietBHBanHangBindingSource.MoveFirst()
        'End If
        'If Me.LayoutControlGroupChatLuong.IsInTabbedGroup Then

        'End If
    End Sub

    Private Sub BarButtonItemPreviousChiTiet_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemPreviousChiTiet.ItemClick
        'If Me.LayoutControlGroupHangHoa.IsInTabbedGroup Then
        '    Me.FKBHBanHangChiTietBHBanHangBindingSource.MovePrevious()
        'End If
        'If Me.LayoutControlGroupChatLuong.IsInTabbedGroup Then

        'End If
    End Sub

    Private Sub BarButtonItemNextChiTiet_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemNextChiTiet.ItemClick
        'If Me.LayoutControlGroupHangHoa.IsInTabbedGroup Then
        '    Me.FKBHBanHangChiTietBHBanHangBindingSource.MoveNext()
        'End If
        'If Me.LayoutControlGroupChatLuong.IsInTabbedGroup Then

        'End If
    End Sub

    Private Sub BarButtonItemLastChiTiet_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemLastChiTiet.ItemClick
        'If Me.LayoutControlGroupHangHoa.IsInTabbedGroup Then
        '    Me.FKBHBanHangChiTietBHBanHangBindingSource.MoveLast()
        'End If
        'If Me.LayoutControlGroupChatLuong.IsInTabbedGroup Then

        'End If
    End Sub
    '============= bắt lỗi igridview1 =========================
    Private Sub IGridView1_ShownEditor(ByVal sender As Object, ByVal e As System.EventArgs) Handles IGridView1.ShownEditor
        Dim view As ColumnView = CType(sender, ColumnView)
        view.ActiveEditor.IsModified = True
    End Sub

    Private Sub IGridView1_ValidatingEditor(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs) Handles IGridView1.ValidatingEditor
        If Me.IGridView1.FocusedColumn.FieldName = "taikhoanno" And IGridView1.FocusedRowHandle <> -999997 Then
            If IsDBNull(e.Value) Or IsNothing(e.Value) Then
                e.ErrorText = "không được rỗng !"
                e.Valid = False
                Exit Sub
            ElseIf e.Value.ToString.Trim = "" Then
                e.ErrorText = "không được rỗng !"
                e.Valid = False
                Exit Sub
            End If
        ElseIf Me.IGridView1.FocusedColumn.FieldName = "taikhoanco" And IGridView1.FocusedRowHandle <> -999997 Then
            If IsDBNull(e.Value) Or IsNothing(e.Value) Then
                e.ErrorText = "không được rỗng !"
                e.Valid = False
            ElseIf e.Value.ToString.Trim = "" Then
                e.ErrorText = "không được rỗng !"
                e.Valid = False
            End If
        ElseIf Me.IGridView1.FocusedColumn.FieldName = "mahang" And IGridView1.FocusedRowHandle <> -999997 Then
            If IsDBNull(e.Value) Or IsNothing(e.Value) Then
                e.ErrorText = "không được rỗng !"
                e.Valid = False
            ElseIf e.Value.ToString.Trim = "" Then
                e.ErrorText = "không được rỗng !"
                e.Valid = False
            End If
        ElseIf Me.IGridView1.FocusedColumn.FieldName = "solo" And IGridView1.FocusedRowHandle <> -999997 Then
            If IsDBNull(e.Value) Or IsNothing(e.Value) Then
                e.ErrorText = "không được rỗng !"
                e.Valid = False
            ElseIf e.Value.ToString.Trim = "" Then
                e.ErrorText = "không được rỗng !"
                e.Valid = False
            End If
        ElseIf Me.IGridView1.FocusedColumn.FieldName = "hsd" And IGridView1.FocusedRowHandle <> -999997 Then
            If IsDBNull(e.Value) Or IsNothing(e.Value) Then
                e.ErrorText = "không được rỗng !"
                e.Valid = False
            ElseIf e.Value.ToString.Trim = "" Then
                e.ErrorText = "không được rỗng !"
                e.Valid = False
            End If
        ElseIf Me.IGridView1.FocusedColumn.FieldName = "soluongSO" And IGridView1.FocusedRowHandle <> -999997 Then
            If IsDBNull(e.Value) Or IsNothing(e.Value) Then
                e.ErrorText = "không được rỗng !"
                e.Valid = False
            ElseIf e.Value.ToString.Trim = "" Then
                e.ErrorText = "không được rỗng !"
                e.Valid = False
            ElseIf CDec(e.Value) = 0 Then
                e.ErrorText = "không được bằng 0 !"
                e.Valid = False
            End If
        ElseIf Me.IGridView1.FocusedColumn.FieldName = "soluonggiao" And IGridView1.FocusedRowHandle <> -999997 Then
            If IsDBNull(e.Value) Or IsNothing(e.Value) Then
                e.ErrorText = "không được rỗng !"
                e.Valid = False
            ElseIf e.Value.ToString.Trim = "" Then
                e.ErrorText = "không được rỗng !"
                e.Valid = False
            ElseIf CDec(e.Value) = 0 Then
                e.ErrorText = "không được bằng 0 !"
                e.Valid = False
            End If
        ElseIf Me.IGridView1.FocusedColumn.FieldName = "tilethueGTGT" And IGridView1.FocusedRowHandle <> -999997 Then
            If IsDBNull(e.Value) Or IsNothing(e.Value) Then
                e.ErrorText = "không được rỗng !"
                e.Valid = False
            ElseIf e.Value.ToString.Trim = "" Then
                e.ErrorText = "không được rỗng !"
                e.Valid = False
            End If
        ElseIf Me.IGridView1.FocusedColumn.FieldName = "tienthueGTGT" And IGridView1.FocusedRowHandle <> -999997 Then
            If IsDBNull(e.Value) Or IsNothing(e.Value) Then
                e.ErrorText = "không được rỗng !"
                e.Valid = False
            ElseIf e.Value.ToString.Trim = "" Then
                e.ErrorText = "không được rỗng !"
                e.Valid = False
            End If
        End If
    End Sub
End Class
